package com.prs.crm.action.assets;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.action.ReportAction;
import com.prs.crm.context.AppContext;
import com.prs.crm.domain.assets.AssetsBigClass;
import com.prs.crm.domain.assets.AssetsLingYong;
import com.prs.crm.domain.assets.AssetsRegister;
import com.prs.crm.domain.assets.AssetsRevert;
import com.prs.crm.domain.assets.AssetsScrap;
import com.prs.crm.domain.assets.AssetsSmallClass;
import com.prs.crm.domain.assets.LingYongHistory;
import com.prs.crm.domain.assets.RevertHistory;
import com.prs.crm.report.ExcelExport;
import com.prs.crm.report.ExportConfig;
import com.prs.crm.report.ReportCell;
import com.prs.crm.report.ReportTable;

public class AssetsRegisterReport extends ReportAction{
	private AssetsRegister assetsRegister;
	private AssetsLingYong assetsLingYong;
	private AssetsRevert assetsRevert;
	private AssetsScrap assetsScrap;
	private AssetsBigClass assetsBigClass;
	private AssetsSmallClass assetsSmallClass;
	
	public AssetsBigClass getAssetsBigClass() {
		return assetsBigClass;
	}

	public void setAssetsBigClass(AssetsBigClass assetsBigClass) {
		this.assetsBigClass = assetsBigClass;
	}

	public AssetsSmallClass getAssetsSmallClass() {
		return assetsSmallClass;
	}

	public void setAssetsSmallClass(AssetsSmallClass assetsSmallClass) {
		this.assetsSmallClass = assetsSmallClass;
	}

	public AssetsRegister getAssetsRegister() {
		return assetsRegister;
	}

	public void setAssetsRegister(AssetsRegister assetsRegister) {
		this.assetsRegister = assetsRegister;
	}

	public AssetsLingYong getAssetsLingYong() {
		return assetsLingYong;
	}

	public void setAssetsLingYong(AssetsLingYong assetsLingYong) {
		this.assetsLingYong = assetsLingYong;
	}

	public AssetsRevert getAssetsRevert() {
		return assetsRevert;
	}

	public void setAssetsRevert(AssetsRevert assetsRevert) {
		this.assetsRevert = assetsRevert;
	}

	public AssetsScrap getAssetsScrap() {
		return assetsScrap;
	}

	public void setAssetsScrap(AssetsScrap assetsScrap) {
		this.assetsScrap = assetsScrap;
	}

	@Action(value = "exportAssetsRegisterReport", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrder() {
		ReportTable table = new ReportTable("资产月折旧");
		table.addCell(new ReportCell("资产编号", "num"));
		table.addCell(new ReportCell("资产名称", "name"));
		table.addCell(new ReportCell("当前状态", "state"));
		table.addCell(new ReportCell("资产原值", "fpje"));
		table.addCell(new ReportCell("折旧年月", "zjnow"));
		table.addCell(new ReportCell("本月折旧值", "zjCurrentMonth"));
		table.addCell(new ReportCell("本月残值", "czMonth"));
		table.addCell(new ReportCell("已折旧月数", "zjmonth"));
		table.addCell(new ReportCell("已折旧总值", "zjAll"));
		table.addCell(new ReportCell("折旧开始年月", "zjstart"));

		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				AssetsRegister.class).add(Restrictions.isNotNull("isZJ"));
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	
	/**********资产台账导出***********/
	
	@Action(value = "exportAssetsTaizhangReport", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrder1() {
		ReportTable table = new ReportTable("资产月折旧");
		assetsLingYong=new AssetsLingYong();
		assetsBigClass=new AssetsBigClass();
		assetsSmallClass=new AssetsSmallClass();
		table.addCell(new ReportCell("资产编号", "num"));
		table.addCell(new ReportCell("资产名称", "name"));
		table.addCell(new ReportCell("规格", "guige"));
		table.addCell(new ReportCell("所属大类", "assetsBigClass.name"));
		table.addCell(new ReportCell("所属小类", "assetsSmallClass.name"));
		table.addCell(new ReportCell("发票金额", "fpje"));
		table.addCell(new ReportCell("发票日期", "zjnow"));
		table.addCell(new ReportCell("残值率", "canzhi"));
		table.addCell(new ReportCell("资产状态", "state"));
		table.addCell(new ReportCell("资产净值", "zcjz"));
		table.addCell(new ReportCell("资产残值", "zccz"));
		table.addCell(new ReportCell("使用人", "assetsLingYong.luser"));

		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				AssetsRegister.class);
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	
	@Action(value = "exportAssetsLiuXiangReport", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrders() {
		ReportTable report =new ReportTable("资产当前流向");
		assetsLingYong=new AssetsLingYong();
		assetsRevert=new AssetsRevert();
		assetsScrap=new AssetsScrap();
		report.addCell(new ReportCell("资产编号","num"));
		report.addCell(new ReportCell("资产名称","name"));
		report.addCell(new ReportCell("当前状态","state"));
		
//		if (assetsRegister.getAssetsLingYong()!=null) {
//			report.addCell(new ReportCell("负责人部门","assetsLingYong.ldep"));
//			report.addCell(new ReportCell("负责人","assetsLingYong.luser"));
//			report.addCell(new ReportCell("日期","assetsLingYong.ldate"));
//		}
//		if(assetsRegister.getAsssteRevert()!=null){
//			report.addCell(new ReportCell("负责人部门","dept"));
//			report.addCell(new ReportCell("负责人","user"));
//			report.addCell(new ReportCell("日期","date"));
//		}
//		if(assetsRegister.getAssetsScrap()!=null){
//			report.addCell(new ReportCell("负责人部门","dept"));
//			report.addCell(new ReportCell("负责人","name"));
//			report.addCell(new ReportCell("日期","date"));
//		}
//		if(assetsLingYong.getLuser()!=null){
//			report.addCell(new ReportCell("负责人","luser"));
//		}
//		if(assetsRevert.getUser()!=null){
//			report.addCell(new ReportCell("负责人","user"));
//		}
//		if(assetsScrap.getName()!=null){
//			report.addCell(new ReportCell("负责人","name"));
//		}
//		if(assetsLingYong.getLdate()!=null){
//			report.addCell(new ReportCell("日期","ldate"));
//		}
//		if(assetsRevert.getDate()!=null){
//			report.addCell(new ReportCell("日期","date"));
//		}
//		if(assetsScrap.getDate()!=null){
//			report.addCell(new ReportCell("日期","date"));
//		}
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(AssetsRegister.class)
		.add(Restrictions.or(Restrictions.or(Restrictions.isNotNull("asssteRevert"), Restrictions.isNotNull("assetsLingYong")), Restrictions.isNotNull("assetsScrap")));
		this.setOutFilePath(this.getReportService().exportAssetsLiuXiang(criteria, report, new ExportConfig(),this.getExportType()));
		return SUCCESS;
	}
	/**领用明细导出****/
	@Action(value = "reportOrderLingYong", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrderLingYong() {
		ReportTable table = new ReportTable("领用明细");
		assetsLingYong=new AssetsLingYong();
		assetsBigClass=new AssetsBigClass();
		assetsSmallClass=new AssetsSmallClass();
		table.addCell(new ReportCell("领用编号", "number"));
		table.addCell(new ReportCell("领用说明", "shuoming"));
		table.addCell(new ReportCell("领用人", "luser"));
		table.addCell(new ReportCell("领用人部门", "ldep"));
		table.addCell(new ReportCell("领用日期", "ldate"));
		table.addCell(new ReportCell("资产编号", ""));
		table.addCell(new ReportCell("资产名称", ""));
		table.addCell(new ReportCell("规格", ""));

		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				AssetsLingYong.class);
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	
	/**归还明细导出****/
	@Action(value = "reportOrderRevert", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrderRevert() {
		ReportTable table = new ReportTable("归还明细");
		assetsLingYong=new AssetsLingYong();
		assetsBigClass=new AssetsBigClass();
		assetsSmallClass=new AssetsSmallClass();
		table.addCell(new ReportCell("归还编号", "number"));
		table.addCell(new ReportCell("归还人", "user"));
		table.addCell(new ReportCell("归还人部门", "dept"));
		table.addCell(new ReportCell("归还日期", "date"));
		table.addCell(new ReportCell("资产编号", ""));
		table.addCell(new ReportCell("资产名称", ""));
		table.addCell(new ReportCell("规格", ""));
		table.addCell(new ReportCell("资产情况说明", "shuoming"));

		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				AssetsRevert.class);
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	
	/**报废明细导出****/
	@Action(value = "reportOrderScrap", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrderScrap() {
		ReportTable table = new ReportTable("报废明细");
		assetsLingYong=new AssetsLingYong();
		assetsBigClass=new AssetsBigClass();
		assetsSmallClass=new AssetsSmallClass();
		table.addCell(new ReportCell("申请单号", "number"));
		table.addCell(new ReportCell("资产编号", ""));
		table.addCell(new ReportCell("资产名称", ""));
		table.addCell(new ReportCell("规格", ""));
		table.addCell(new ReportCell("报废原因", "cause"));

		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				AssetsScrap.class);
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	/**在用资产导出****/
	@Action(value = "reportOrderAssets", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrderAssets() {
		ReportTable table = new ReportTable("在用资产");
		assetsLingYong=new AssetsLingYong();
		assetsBigClass=new AssetsBigClass();
		assetsSmallClass=new AssetsSmallClass();
		table.addCell(new ReportCell("资产编号", "num"));
		table.addCell(new ReportCell("资产名称", "name"));
		table.addCell(new ReportCell("规格", "guige"));
		table.addCell(new ReportCell("发票金额", "fpje"));
		table.addCell(new ReportCell("发票日期", "fprq"));
		table.addCell(new ReportCell("资产净值", "zcjz"));
		table.addCell(new ReportCell("资产残值", "zccz"));
		table.addCell(new ReportCell("所属大类", "assetsBigClass.name"));
		table.addCell(new ReportCell("所属小类", "assetsSmallClass.name"));
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(AssetsRegister.class)
		.createAlias("assetsLingYong", "ly").add(Restrictions.eq("state", "领用"))
		.add(Restrictions.eq("ly.person.id", AppContext.getAccountContext().getUser().getId()));
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	/**领用历史导出****/
	@Action(value = "reportOrderLingYongHistory", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrderLingYongHistory() {
		ReportTable table = new ReportTable("领用历史");
		assetsLingYong=new AssetsLingYong();
		assetsBigClass=new AssetsBigClass();
		assetsSmallClass=new AssetsSmallClass();
		table.addCell(new ReportCell("领用编号", "number"));
		table.addCell(new ReportCell("领用说明", "shuoming"));
		table.addCell(new ReportCell("领用日期", "ldate"));
		table.addCell(new ReportCell("资产编号", ""));
		table.addCell(new ReportCell("资产名称", ""));
		table.addCell(new ReportCell("规格", ""));

		DetachedCriteria criteria = this.getPaginationHelper().createQuery(LingYongHistory.class)
		.add(Restrictions.eq("person.id", AppContext.getAccountContext().getUser().getId()));
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
	
	/**归还历史导出****/
	@Action(value = "reportOrderRevertHistory", results = { @Result(name = "success", type = "stream", params = {
			"contentType", "${contentType}", "inputName", "inputStream",
			"bufferSize", "1024", "contentDisposition",
			"filename=${outfileName}" }) })
	public String reportOrderRevertHistory() {
		ReportTable table = new ReportTable("归还明细");
		assetsLingYong=new AssetsLingYong();
		assetsBigClass=new AssetsBigClass();
		assetsSmallClass=new AssetsSmallClass();
		table.addCell(new ReportCell("入库单单号", "number"));
		table.addCell(new ReportCell("归还日期", "date"));
		table.addCell(new ReportCell("资产编号", ""));
		table.addCell(new ReportCell("资产名称", ""));
		table.addCell(new ReportCell("规格", ""));
		table.addCell(new ReportCell("资产情况说明", "shuoming"));

		DetachedCriteria criteria = this.getPaginationHelper().createQuery(RevertHistory.class)
		.add(Restrictions.eq("person.id", AppContext.getAccountContext().getUser().getId()));
		this.setOutFilePath(this.getReportService().exportAlreadyDistribution(
				criteria, table, new ExportConfig(), this.getExportType()));
		return SUCCESS;
	}
}
